﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BusinessObject;
using System.IO;
using Entity;
using System.Data;

namespace GreenLife.Admin
{
    public partial class ThemDanhMucCon : System.Web.UI.Page
    {
        SubCategoriesBO scBO = new SubCategoriesBO();
        CategoriesBO cBO = new CategoriesBO();
        DataSet ds = null;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                selectCate();
            Bind_ddlState();
            }
        }

        private void selectCate()
        {
            ddlTower.Items.Add("Tower A");
            ddlTower.Items.Add("Tower B");
        }
        private void Bind_ddlState() {
            ds = cBO.selectCategoryByType(ddlTower.SelectedValue.ToString());
            ddlCate.DataSource = ds.Tables[0];
            ddlCate.Items.Clear();
            ddlCate.DataTextField = "CategoryName";
            ddlCate.DataValueField = "CategoryID";
            ddlCate.DataBind();
        }

        protected void ddlTower_SelectedIndexChanged(object sender, EventArgs e)
        {
            Bind_ddlState();
        }
        protected void ddlCate_SelectedIndexChanged(object sender, EventArgs e)
        {
        }
        protected void btnAdd_Click(object sender, EventArgs e)
        {
            string imgFileName = Path.GetFileName(FileUploadControl.FileName);
            if (imgFileName.Equals("") == true)
            {
                imgFileName = "greenlifelogo.jpg";
            }
            else
            {
                FileUploadControl.SaveAs(Server.MapPath("~/imageUpload/") + imgFileName);
            }
            if (scBO.createSubCategory(Int32.Parse(ddlCate.SelectedValue.ToString()), txtSubCateName.Text, "~/imageUpload/" + imgFileName, txtDescription.Text, float.Parse(txtSubCateArea.Text), txtSubCateHuong.Text))
            {
                Response.Redirect("DanhSachDanhMucCon.aspx");
            }
            else
            {
                Response.Redirect("error.aspx");
            }
        }

    }
}